package com.maven.front.controller.frontIndex;

import com.maven.front.bean.EduCourse;
import com.maven.front.bean.Result;
import com.maven.front.service.frontIndex.FrontIndexService;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * @program: web-front
 * @description: 前台首页
 * @author: WangYiLong
 * @create: 2020-08-11 13:58
 **/
@RestController
@RequestMapping("user")
public class FrontIndexController {

    @Resource
    private FrontIndexService frontIndexService;

    /**
     * 首页精品课程显示
     * @return
     */
    @GetMapping("index/recommendCourse")
    public Result recommendCourse(){
        List<EduCourse> list = frontIndexService.getRecommendCourse();
        if(CollectionUtils.isEmpty(list)){
            return new Result(508,"无推荐课程");
        }
        return new Result(200,"成功",list);
    }

    /**
     * 首页最新课程显示
     * @return
     */
    @GetMapping("index/freshCourse")
    public Result freshCourse(){
        List<EduCourse> list = frontIndexService.freshCourse();
        if(CollectionUtils.isEmpty(list)){
            return new Result(509,"无最新课程");
        }
        return new Result(200,"成功",list);
    }

    /**
     * 所有课程
     * @return
     */
    @GetMapping("index/allCourse")
    public Result list(){
        List<EduCourse> list = frontIndexService.selectAll();
        if(CollectionUtils.isEmpty(list)){
            return new Result(510,"查询失败");
        }
        return new Result(200,"成功",list);
    }


    /**
     * 首页
     * @return
     */
    @GetMapping("index")
    public Result index(){
        Map map = frontIndexService.getIndex();
        if(CollectionUtils.isEmpty(map)){
            return new Result(510,"查询失败");
        }
        return new Result(200,"成功",map);
    }

}
